package com.gxa.controller.set;

import com.gxa.common.R;
import com.gxa.entity.DistrictSysOrganization;
import com.gxa.service.DistrictOrganizationService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/districtOrganization")
@Api(value = "组织管理的所有操作测试",tags = "组织管理接口API")
public class DistrictOrganizationController {

    @Autowired
    private DistrictOrganizationService districtOrganizationService;

    /**
     * 分页查询对应区级的所有组织信息
     * @param currentPage
     * @param pageSize
     * @param topOrganization
     * @return
     */
    @RequestMapping(value = "/queryAllOrganizationsByPage",method = RequestMethod.GET)
    @ApiOperation(value = "分页查询对应区级的组织信息接口",notes = "查询对应区级的所有组织进行分页显示",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "topOrganization",value = "最上层组织",required = true,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryAllOrganizationsByPage(int currentPage,int pageSize,String topOrganization){
        return districtOrganizationService.queryAllOrganizationsByPage(currentPage,pageSize,topOrganization);
    }

    /**
     * 添加组织信息
     * @param districtSysOrganization
     * @return
     */
    @RequestMapping(value = "/addOrganization",method = RequestMethod.POST)
    @ApiOperation(value = "添加组织接口",notes = "添加组织信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误"),
            @ApiResponse(code=1001,message="添加失败，要添加的组织已存在！")
    })
    @ResponseBody
    public R addOrganization(@RequestBody @ApiParam(name = "districtSysOrganization",value = "组织信息",required = true) DistrictSysOrganization districtSysOrganization){
        return districtOrganizationService.addOrganization(districtSysOrganization);
    }

    /**
     * 修改组织信息
     * @param districtSysOrganization
     * @return
     */
    @RequestMapping(value = "/updateOrganization",method = RequestMethod.POST)
    @ApiOperation(value = "修改组织接口",notes = "修改组织信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R updateOrganization(@RequestBody @ApiParam(name = "districtSysOrganization",value = "组织信息",required = true) DistrictSysOrganization districtSysOrganization){
        return districtOrganizationService.updateOrganization(districtSysOrganization);
    }

    /**
     * 根据组织编号删除组织信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteOrganization",method = RequestMethod.POST)
    @ApiOperation(value = "删除组织接口",notes = "根据组织编号删除组织信息",httpMethod = "POST",response = R.class)
    @ApiImplicitParam(name = "id",value = "要删除的组织编号",required = true,dataType = "int",paramType = "query")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R deleteOrganization(int id){
        return districtOrganizationService.deleteOrganizationById(id);
    }

    /**
     * 查询对应区级的所有组织信息
     * @param topOrganization
     * @return
     */
    @RequestMapping(value = "/queryAllOrganizations",method = RequestMethod.GET)
    @ApiOperation(value = "查询对应区级的组织信息接口",notes = "查询对应区级的所有组织进行显示",httpMethod = "GET",response = R.class)
    @ApiImplicitParam(name = "topOrganization",value = "最上层组织",required = true,dataType = "String",paramType = "query")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryAllOrganizations(String topOrganization){
        return districtOrganizationService.queryAllOrganizations(topOrganization);
    }
}
